﻿using CoreShop.Model;
using CoreShop.Services;
using FastMember;
using SqlSugar.Extensions;
using Sunny.UI;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreShop.Library;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Windows.Forms;
using System.IO;

namespace CoreShop.PrintService
{
    public class PrinterUnits
    {
        public static void ShowPrintBillSet(corecmsprintscheme _corecmsprintscheme, 
            corecmsprintbilltemplate _printbilltemplate,int type,int billtypeId,int foodPrintType)
        {
            var frm = new frmPrintManagerIP(_corecmsprintscheme, _printbilltemplate, type, billtypeId, foodPrintType);
            frm.ShowDialog();
            frm.Dispose();
        }

        /// <summary>
        /// 复制生成报表文件
        /// </summary>
        public static string GetReportFileName(corecmsprintbilltype printbilltype, int mPageSize)
        {
            try
            {
                if (printbilltype == null) return "";
                string reportFile = printbilltype.reportFile58;
                string sourceFile = System.Windows.Forms.Application.StartupPath + "\\report\\template\\";
                if (mPageSize != (int)PageSize.W58) reportFile = printbilltype.reportFile80;
                sourceFile = sourceFile + reportFile;

                if (!File.Exists(sourceFile)) return "";
                string newFileStr = "_" + CommFunc.GetTimeStamp().ToString() + ".grf";
                string newRptFile = reportFile.Replace(".grf", newFileStr);
                bool isrewrite = true;
                string targetPath = System.Windows.Forms.Application.StartupPath + "\\report\\" + newRptFile;
                System.IO.File.Copy(sourceFile, targetPath, isrewrite);
                return newRptFile;
            }
            catch { }
            return "";
        }


        public static void ShowPrinterState()
        {
            var frm = new frmPrinterState();
            frm.ShowDialog();
            frm.Dispose();
        }
    }



}
